package com.my.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.my.entity.StudentTestPaper;
import com.my.entity.Token;
import com.my.service.StudentTestPaperService;
import com.my.service.TokenService;
import com.my.util.Rest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class StudentTestPaperController {

    @Resource
    private StudentTestPaperService service;

    @Resource
    private TokenService tService;

    @PostMapping("studentTestPaper/get")
    public Rest get(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize, @RequestBody StudentTestPaper s) {
        return Rest.ok().setData("page", service.getPage(new Page<>(pageNo, pageSize), s));
    }

    @PostMapping("studentScoreLog/get")
    public Rest get(@RequestHeader("authentication-token") String to, @RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize, @RequestBody StudentTestPaper s) {
        Token token = tService.getById(to);
        s.getStudent().setId(token.getUserId());
        return Rest.ok().setData("page", service.getPage(new Page<>(pageNo, pageSize), s));
    }

}
